<?php

namespace App\Http\Controllers;

use App\Services\JwtService;
use Illuminate\Http\Request;

class TokenController extends Controller
{
    /**
     * @throws \Exception
     */
    public function refreshToken(Request $request): array
    {
        $token = $request->input('refresh_token');
        $jwtService = new JwtService();
        $jwt = $jwtService->parseToken($token);
        $newToken = $jwtService->createToken($jwt->data['id'], $jwt->data['type']);
        return ['code' => 200, 'data' => ['access_token' => $newToken, 'msg' => 'ok']];
    }
}
